package com.nervenets.web.controller.handler.admin.setting;

import com.nervenets.web.controller.handler.SessionHandler;
import com.nervenets.web.entity.MessageCode;
import com.nervenets.web.enumeration.Role;
import com.nervenets.web.hibernate.domain.setting.Help;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

public class HelpEditHandler extends SessionHandler<HelpEditParams> {
    @Override
    public ArrayList<Role> allowRoles() {
        return Role.administrator();
    }

    @Override
    public boolean needLog() {
        return false;
    }

    @Override
    public String handle(HelpEditParams params, HttpServletRequest request) throws Exception {
        Help help = new Help();
        if (params.getHelpId() > 0) {
            help = userDao.findById(params.getHelpId(), Help.class);
            if (null == help) return errorMessage(MessageCode.code_444, "您要修改的帮助文档不存在！");
        }
        help.setTagId(params.getTagId());
        help.setTitle(params.getTitle());
        help.setContent(params.getContent());
        help.setQueue(params.getQueue());
        userDao.saveOrUpdate(help);
        return successMessage();
    }

    @Override
    public String result() throws Exception {
        return null;
    }
}
